﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="Employee", Namespace="http://kis.x-road.eu/", Target=typeof(Employee))]
    public class EmployeeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected Employee clazz;
        
        public EmployeeSerializer(Employee clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("FirstName");
            if (clazz.FirstName!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdToken(((string)(clazz.FirstName))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : FirstName");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("LastName");
            if (clazz.LastName!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdToken(((string)(clazz.LastName))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : LastName");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Age");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.Age))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("Genger");
            if (clazz.Genger!=null) {
                Writer.WriteString(clazz.Genger.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Genger");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("BirthDate");
            if (clazz.BirthDate!=null) {
                Writer.WriteString(clazz.BirthDate.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : BirthDate");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Salary");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.Salary))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("Employer");
            if (clazz.Employer!=null) {
                global::Xtee.Core.SerializationMetadata metaEmployer = this.GetMetaData(clazz.Employer);
                if (ShouldWriteTypeAttribute(typeof(global::Kis.Xroad.Eu.Employee), clazz.Employer.GetType())) {
                    Writer.WriteTypeAttribute(metaEmployer.TypeQualifiedName.Namespace, metaEmployer.TypeQualifiedName.Name);
                }
                var employerSerializer = metaEmployer.NewSerializer(clazz.Employer);
                employerSerializer.WriteXmlAttributes(Writer);
                employerSerializer.WriteXml(Writer);
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Department");
            if (clazz.Department!=null) {
                global::Xtee.Core.SerializationMetadata metaDepartment = this.GetMetaData(clazz.Department);
                if (ShouldWriteTypeAttribute(typeof(Employee.DepartmentType), clazz.Department.GetType())) {
                    Writer.WriteTypeAttribute(metaDepartment.TypeQualifiedName.Namespace, metaDepartment.TypeQualifiedName.Name);
                }
                var departmentSerializer = metaDepartment.NewSerializer(clazz.Department);
                departmentSerializer.WriteXmlAttributes(Writer);
                departmentSerializer.WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Department");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("DaysOff");
            if (clazz.DaysOff!=null) {
                for (int x = 0; ((clazz.DaysOff != null) 
                            && (x < clazz.DaysOff.Count)); x = (x + 1)) {
                    if (clazz.DaysOff[x]!=null) {
                        Writer.WriteStartElement("item");
                        Writer.WriteString(clazz.DaysOff[x].ToString());
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : DaysOff");
            }
            Writer.WriteEndElement();
            if (clazz.Subordinates!=null) {
                Writer.WriteStartElement("Subordinates");
                if (((clazz.Subordinates == null) 
                            || (clazz.Subordinates.Count < 1m))) {
                    throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "item");
                }
                for (int x = 0; ((clazz.Subordinates != null) 
                            && (x < clazz.Subordinates.Count)); x = (x + 1)) {
                    Writer.WriteStartElement("item");
                    if (clazz.Subordinates[x]!=null) {
                        global::Xtee.Core.SerializationMetadata metaSubordinates = this.GetMetaData(clazz.Subordinates[x]);
                        if (ShouldWriteTypeAttribute(typeof(global::Kis.Xroad.Eu.Employee), clazz.Subordinates[x].GetType())) {
                            Writer.WriteTypeAttribute(metaSubordinates.TypeQualifiedName.Namespace, metaSubordinates.TypeQualifiedName.Name);
                        }
                        var subordinatesSerializer = metaSubordinates.NewSerializer(clazz.Subordinates[x]);
                        subordinatesSerializer.WriteXmlAttributes(Writer);
                        subordinatesSerializer.WriteXml(Writer);
                    }
                    else {
                        Writer.WriteAttributeString("xsi", "nil", null, "1");
                    }
                    Writer.WriteEndElement();
                }
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("Roles");
            if (clazz.Roles!=null) {
                for (int x = 0; ((clazz.Roles != null) 
                            && (x < clazz.Roles.Count)); x = (x + 1)) {
                    if (clazz.Roles[x]!=null) {
                        Writer.WriteStartElement("item");
                        Writer.WriteString(clazz.Roles[x].ToString());
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("ManagedRegions");
            if (clazz.ManagedRegions!=null) {
                for (int x = 0; ((clazz.ManagedRegions != null) 
                            && (x < clazz.ManagedRegions.Count)); x = (x + 1)) {
                    if (clazz.ManagedRegions[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaManagedRegions = this.GetMetaData(clazz.ManagedRegions[x]);
                        if (ShouldWriteTypeAttribute(typeof(Employee.ManagedRegionsType), clazz.ManagedRegions[x].GetType())) {
                            Writer.WriteTypeAttribute(metaManagedRegions.TypeQualifiedName.Namespace, metaManagedRegions.TypeQualifiedName.Name);
                        }
                        var managedRegionsSerializer = metaManagedRegions.NewSerializer(clazz.ManagedRegions[x]);
                        managedRegionsSerializer.WriteXmlAttributes(Writer);
                        managedRegionsSerializer.WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ManagedRegions");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="FirstName") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Employee>FirstName");
                }
                clazz.FirstName = new global::Xtee.Core.Schema.XsdToken(Reader.ReadElementString("FirstName")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Employee>FirstName", Reader.LocalName);
            }
            if (Reader.LocalName=="LastName") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Employee>LastName");
                }
                clazz.LastName = new global::Xtee.Core.Schema.XsdToken(Reader.ReadElementString("LastName")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Employee>LastName", Reader.LocalName);
            }
            if (Reader.LocalName=="Age") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Employee>Age");
                }
                clazz.Age = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("Age")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Employee>Age", Reader.LocalName);
            }
            if (Reader.LocalName=="Genger") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Employee>Genger");
                }
                clazz.Genger = new global::Kis.Xroad.Eu.Gender(Reader.ReadElementString("Genger"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Employee>Genger", Reader.LocalName);
            }
            if (Reader.LocalName=="BirthDate") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Employee>BirthDate");
                }
                clazz.BirthDate = new Employee.BirthDateType(Reader.ReadElementString("BirthDate"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Employee>BirthDate", Reader.LocalName);
            }
            if (Reader.LocalName=="Salary") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Employee>Salary");
                }
                clazz.Salary = new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("Salary")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Employee>Salary", Reader.LocalName);
            }
            if (Reader.LocalName=="Employer") {
                if ((Reader.IsElementNil() == false)) {
                    global::Xtee.Core.SerializationMetadata metaEmployer = this.GetMetaData<global::Kis.Xroad.Eu.Employee>(Reader, "Employee", "http://kis.x-road.eu/");
                    clazz.Employer = metaEmployer.NewEntity<global::Kis.Xroad.Eu.Employee>();
                    if ((Reader.IsEmptyElement == false)) {
                        var employerSerializer = metaEmployer.NewSerializer(clazz.Employer);
                        employerSerializer.ReadXmlAttributes(Reader);
                        Reader.ReadStartElement("Employer");
                        employerSerializer.ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Employee>Employer", Reader.LocalName);
            }
            if (Reader.LocalName=="Department") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Employee>Department");
                }
                global::Xtee.Core.SerializationMetadata metaDepartment = this.GetMetaData<Employee.DepartmentType>(Reader, ">>Employee>Department", "http://kis.x-road.eu/");
                clazz.Department = metaDepartment.NewEntity<Employee.DepartmentType>();
                if ((Reader.IsEmptyElement == false)) {
                    var departmentSerializer = metaDepartment.NewSerializer(clazz.Department);
                    departmentSerializer.ReadXmlAttributes(Reader);
                    Reader.ReadStartElement("Department");
                    departmentSerializer.ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Employee>Department", Reader.LocalName);
            }
            if (Reader.LocalName=="DaysOff") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Employee>DaysOff");
                }
                clazz.DaysOff = new System.Collections.Generic.List<global::Kis.Xroad.Eu.WorkDay>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("DaysOff");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if ((Reader.IsElementNil() == false)) {
                            clazz.DaysOff.Add(new global::Kis.Xroad.Eu.WorkDay(Reader.ReadElementString("item")));
                        }
                        else {
                            clazz.DaysOff.Add(null);
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Employee>DaysOff", Reader.LocalName);
            }
            if (Reader.LocalName=="Subordinates") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Employee>Subordinates");
                }
                clazz.Subordinates = new System.Collections.Generic.List<global::Kis.Xroad.Eu.Employee>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("Subordinates");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.LocalName=="item") {
                            if ((Reader.IsElementNil() == false)) {
                                global::Xtee.Core.SerializationMetadata metaSubordinates = this.GetMetaData<global::Kis.Xroad.Eu.Employee>(Reader, "Employee", "http://kis.x-road.eu/");
                                global::Kis.Xroad.Eu.Employee item = metaSubordinates.NewEntity<global::Kis.Xroad.Eu.Employee>();
                                clazz.Subordinates.Add(item);
                                if ((Reader.IsEmptyElement == false)) {
                                    var subordinatesSerializer = metaSubordinates.NewSerializer(item);
                                    subordinatesSerializer.ReadXmlAttributes(Reader);
                                    Reader.ReadStartElement("item");
                                    subordinatesSerializer.ReadXml(Reader);
                                    Reader.ReadEndElement();
                                }
                                else {
                                    Reader.Skip();
                                }
                            }
                            else {
                                clazz.Subordinates.Add(null);
                                Reader.Skip();
                            }
                        }
                        else {
                            throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>Employee>Subordinates>item", Reader.LocalName);
                        }
                    }
                    if ((clazz.Subordinates.Count < 1m)) {
                        throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "item");
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Roles") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Roles = new System.Collections.Generic.List<Employee.RolesType>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("Roles");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if ((Reader.IsElementNil() == false)) {
                                clazz.Roles.Add(new Employee.RolesType(Reader.ReadElementString("item")));
                            }
                            else {
                                clazz.Roles.Add(null);
                                Reader.Skip();
                            }
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Employee>Roles", Reader.LocalName);
            }
            if (Reader.LocalName=="ManagedRegions") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Employee>ManagedRegions");
                }
                clazz.ManagedRegions = new System.Collections.Generic.List<Employee.ManagedRegionsType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("ManagedRegions");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if ((Reader.IsElementNil() == false)) {
                            global::Xtee.Core.SerializationMetadata metaManagedRegions = this.GetMetaData<Employee.ManagedRegionsType>(Reader, ">>>Employee>ManagedRegions>item", "http://kis.x-road.eu/");
                            Employee.ManagedRegionsType item = metaManagedRegions.NewEntity<Employee.ManagedRegionsType>();
                            clazz.ManagedRegions.Add(item);
                            if ((Reader.IsEmptyElement == false)) {
                                var managedRegionsSerializer = metaManagedRegions.NewSerializer(item);
                                managedRegionsSerializer.ReadXmlAttributes(Reader);
                                Reader.ReadStartElement("item");
                                managedRegionsSerializer.ReadXml(Reader);
                                Reader.ReadEndElement();
                            }
                            else {
                                Reader.Skip();
                            }
                        }
                        else {
                            clazz.ManagedRegions.Add(null);
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Employee>ManagedRegions", Reader.LocalName);
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>Employee>Department", Namespace="http://kis.x-road.eu/", Target=typeof(Employee.DepartmentType))]
        public class DepartmentTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected Employee.DepartmentType clazz;
            
            public DepartmentTypeSerializer(Employee.DepartmentType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXmlAttributes(Writer);
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                Writer.WriteStartElement("Country");
                if (clazz.Country!=null) {
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Country))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Country");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Floor");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.Floor))).ToString());
                Writer.WriteEndElement();
            }
            
            public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXmlAttributes(Reader);
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="Country") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>Employee>Department>Country");
                    }
                    clazz.Country = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Country")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>Employee>Department>Country", Reader.LocalName);
                }
                if (Reader.LocalName=="Floor") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>Employee>Department>Floor");
                    }
                    clazz.Floor = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("Floor")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>Employee>Department>Floor", Reader.LocalName);
                }
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>>Employee>ManagedRegions>item", Namespace="http://kis.x-road.eu/", Target=typeof(Employee.ManagedRegionsType))]
        public class ManagedRegionsTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected Employee.ManagedRegionsType clazz;
            
            public ManagedRegionsTypeSerializer(Employee.ManagedRegionsType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXmlAttributes(Writer);
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                Writer.WriteStartElement("Country");
                if (clazz.Country!=null) {
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Country))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Country");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("City");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.City))).ToString());
                Writer.WriteEndElement();
                Writer.WriteStartElement("Street");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.Street))).ToString());
                Writer.WriteEndElement();
            }
            
            public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXmlAttributes(Reader);
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="Country") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>Employee>ManagedRegions>item>Country");
                    }
                    clazz.Country = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Country")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>Employee>ManagedRegions>item>Country", Reader.LocalName);
                }
                if (Reader.LocalName=="City") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>Employee>ManagedRegions>item>City");
                    }
                    clazz.City = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("City")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>Employee>ManagedRegions>item>City", Reader.LocalName);
                }
                if (Reader.LocalName=="Street") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>Employee>ManagedRegions>item>Street");
                    }
                    clazz.Street = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("Street")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>Employee>ManagedRegions>item>Street", Reader.LocalName);
                }
            }
        }
    }
}
